package com.simtop.service.impl;

import com.simtop.common.ServerResponse;
import com.simtop.dao.FileDao;
import com.simtop.pojo.File;
import com.simtop.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class FileServiceImpl implements FileService {

    @Autowired
    private FileDao fileDao;

    /**
     * 保存文件路径以及文件名
     * @param file
     */
    @Override
    public ServerResponse<String> addFile(File file) {
        int Count =  fileDao.addFile(file);
        if (Count != 1){
            return ServerResponse.createByErrorMsg("添加失败");
        }
        return ServerResponse.createBySuccessMsg("添加成功");
    }

    /**
     * 通过id查找文件路径
     * @param id
     * @return
     */
    @Override
    public String selectPathById(Integer id) {
        return fileDao.selectPathById(id);
    }

    /**
     * 通过id查找文件名
     * @param id
     * @return
     */
    @Override
    public String selectNameById(Integer id) {
        return fileDao.selectNameById(id);
    }

    @Override
    public String selectFileById(Integer id) {
        return fileDao.selectFileById(id);
    }

    @Override
    public boolean addUpLoadFile(String destFileName) {
        int count = fileDao.addUpLoadFile(destFileName);
        boolean flag =false;
        if (count != 1){
            return flag;
        }
        flag = true;
        return flag;
    }
}
